package com.pls.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.pls.entity.Employee;
import com.pls.entity.EmployeeSeat;
import com.pls.entity.Location;
import com.pls.entity.LocationDetails;
import com.pls.entity.SeatType;

public class EmployeeSeatMapper implements Mapper<EmployeeSeat>{

	public List<EmployeeSeat> MapList(ResultSet rs) throws SQLException {
		
		List<EmployeeSeat> employeeSeatList = null;
		try {
			employeeSeatList = new ArrayList<EmployeeSeat>();
			EmployeeSeat empSeat = null;
			Employee emp = null;
			SeatType st = null;
			Location loc = null;
			LocationDetails locDetails = null;
			while(rs.next()){
				empSeat = new EmployeeSeat();
				emp = new Employee();
				st = new SeatType();
				loc = new Location();
				locDetails = new LocationDetails();
				
				empSeat.setSeatID(rs.getInt("seat_id"));
				empSeat.setLocalNo(rs.getString("local_no"));
				empSeat.setCol(rs.getInt("col"));
				empSeat.setRow(rs.getInt("row"));
				empSeat.setQuadrant(rs.getString("quadrant"));
				empSeat.setSeatCode(rs.getString("seat_code"));
				empSeat.setFloor_level(rs.getString("floor_level"));
				
				// emp.setEmailAddress(rs.getString("email_add"));
				// emp.setFirstName(rs.getString("first_name"));
				// emp.setLastName(rs.getString("last_name"));
				// emp.setPositionCode(rs.getString("position_code"));
				emp.setId(rs.getInt("employee_id"));
				
				empSeat.setEmployee(emp);
				
				st.setSeat_type_code(rs.getString("seat_type_code"));
				st.setSeat_type_desc(rs.getString("seat_type_desc"));
				st.setSeat_type_id(rs.getInt("seat_type_id"));
				
				empSeat.setSeatType(st);
				
				locDetails.setFloorLevel(rs.getString("floor_level"));
				locDetails.setId(rs.getInt("location_detail_id"));
				
				loc.setLocactionDet(locDetails);
				loc.setLocationAddress(rs.getString("location_address"));
				loc.setLocationCode(rs.getString("location_code"));
				loc.setLocationID(rs.getInt("location_id"));
			
				empSeat.setLocation(loc);
				
				
				employeeSeatList.add(empSeat);
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return employeeSeatList;
	}

	@Override
	public EmployeeSeat Map(ResultSet rs) throws SQLException {
		EmployeeSeat empSeat = null;
		try {
			Employee emp = null;
			SeatType st = null;
			Location loc = null;
			LocationDetails locDetails = null;
			while(rs.next()){
				empSeat = new EmployeeSeat();
				emp = new Employee();
				st = new SeatType();
				loc = new Location();
				locDetails = new LocationDetails();
				
				empSeat.setSeatID(rs.getInt("seat_id"));
				empSeat.setLocalNo(rs.getString("local_no"));
				empSeat.setCol(rs.getInt("col"));
				empSeat.setRow(rs.getInt("row"));
				empSeat.setQuadrant(rs.getString("quadrant"));
				empSeat.setSeatCode(rs.getString("seat_code"));
				empSeat.setFloor_level(rs.getString("floor_level"));

				emp.setId(rs.getInt("employee_id"));
				emp.setEmailAddress(rs.getString("email_add"));
				emp.setFirstName(rs.getString("first_name"));
				emp.setLastName(rs.getString("last_name"));
				emp.setPositionCode(rs.getString("position_code"));
				
				
				empSeat.setEmployee(emp);
				
				st.setSeat_type_code(rs.getString("seat_type_code"));
				st.setSeat_type_desc(rs.getString("seat_type_desc"));
				st.setSeat_type_id(rs.getInt("seat_type_id"));
				
				empSeat.setSeatType(st);
				
				locDetails.setFloorLevel(rs.getString("floor_level"));
				locDetails.setId(rs.getInt("location_detail_id"));
				
				loc.setLocactionDet(locDetails);
				loc.setLocationAddress(rs.getString("location_address"));
				loc.setLocationCode(rs.getString("location_code"));
				loc.setLocationID(rs.getInt("location_id"));
			
				empSeat.setLocation(loc);
				
				return empSeat;
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return empSeat;
	}
	
}
